var wordDictionary = function () {
  this.words = [];
};
wordDictionary.prototype.addWord = function (word) {
  const wordN = word.length;

  if (this.words[wordN] == undefined) {
    this.words[wordN] = [word];
  } else {
    this.words[wordN].push(word);
  }
};
wordDictionary.prototype.search = function (word) {
  const wordN = word.length;
  if (this.words[wordN] == undefined) {
    return false;
  }
  if (!word.includes(".")) {
    return this.words[wordN].includes(word);
  }
  const reg = new RegExp(word);
//   正则表达式的方法，用test方法判断是否匹配
// some方法是数组的方法，用来判断数组中的条件是否满足
  return this.words[wordN].some((i) => reg.test(i));
};

var dict = new wordDictionary();
dict.addWord("bad");
dict.addWord("dad");
dict.addWord("mad");

console.log(dict);

console.log(dict.search("pad")); // false
console.log(dict.search("bad")); // true
console.log(dict.search(".ad")); // true
console.log(dict.search("b..")); // true
console.log(dict.search("...")); // true

var wordDictionary = function () {
    this.words = [];
  };
  wordDictionary.prototype.addWord = function (word) {
    const wordN = word.length;
  
    if (this.words[wordN] == undefined) {
      this.words[wordN] = [word];
    } else {
      this.words[wordN].push(word);
    }
  };
  wordDictionary.prototype.search = function (word) {
    const wordN = word.length;
    if (this.words[wordN] == undefined) {
      return false;
    }
    if (!word.includes(".")) {
      return this.words[wordN].includes(word);
    }
    const reg = new RegExp(word);
    return this.words[wordN].some((i) => reg.test(i));
  };